//
//  GoodsIntroduceTableViewCell.swift
//  ZNZXSuperMarket
//
//  Created by 四川中农 on 2018/8/21.
//  Copyright © 2018年 四川中农. All rights reserved.
//

import UIKit

class GoodsIntroduceTableViewCell: UITableViewCell {
    
    @IBOutlet weak var goodsImagev: UIImageView!
    @IBOutlet weak var goodsName: UILabel!
    @IBOutlet weak var price: UILabel!
    @IBOutlet weak var marketPrice: UILabel!
    @IBOutlet weak var totalPrice: UILabel!
    @IBOutlet weak var number: UILabel!
    

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        self.goodsImagev.setCornerRadio(radio: 10, isMask: true)
    }
    
    func reload(withModel model:SiteGoodsModel,count:Int) {
        self.goodsName.text = model.name
        self.goodsImagev.my_setImage(url: model.img, placeholder: Api.header.rawValue)
        
        var currentPrice:Double = 0
        if model.isDiscount == 1 {
            currentPrice = model.discountMoney
        }else if model.isActivity == 1 {
            currentPrice = model.activityMoney
        }else if model.peddlersPrice != nil {
            currentPrice = Double.init((model.peddlersPrice)!)!
        }else{
            currentPrice = model.price
        }
        
        let str = "￥" + "\(currentPrice)" + "/" + model.spec + "  " + model.specDesc
        let attribute = NSMutableAttributedString.init(string: str)
        attribute.addAttributes([NSAttributedStringKey.font:UIFont.systemFont(ofSize: 11)], range: NSString.init(string: str).range(of: model.specDesc))
        self.price.attributedText = attribute
        
        self.marketPrice.attributedText = Utils.labelTextDeleLine(normalString: "市场价：¥\(model.marketPrice)", deleString: "\(model.marketPrice)")
        
        var attributeString = NSMutableAttributedString.init(string: "小计：¥" + "\(currentPrice * Double(count))")
        attributeString.addAttributes([NSAttributedStringKey.font:UIFont.systemFont(ofSize: 16)], range: NSString.init(string: "小计：¥" + "\(currentPrice * Double(count))").range(of: "\(currentPrice * Double(count))".getPriceInteger()))
        attributeString = NSMutableAttributedString.init(attributedString: attributeString)
        attributeString.addAttributes([NSAttributedStringKey.foregroundColor:UIColor.init(hexColor: "#ed4848")], range: NSString.init(string: "小计：¥" + "\(currentPrice * Double(count))").range(of: "¥" + "\(currentPrice * Double(count))"))
        self.totalPrice.attributedText = attributeString
        
        self.number.text = (model.specDesc == "" ? "" : model.specDesc + "×") + "\(count)" + model.spec
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
